<template>
  <view>
    <view v-if="false"><!-- 这个视图在App.vue中不会显示，只是为了符合Vue的格式要求 --></view>
  </view>
</template>

<script>
import request from '@/utils/request'

export default {
  globalData: {
    userInfo: null,
    isGuest: true
  },
  onLaunch: function() {
    console.log('App Launch');
    
    // 检查登录状态
    const token = uni.getStorageSync('token')
    const isGuest = uni.getStorageSync('isGuest')
    
    this.globalData.isGuest = isGuest || !token
    
    // 添加请求拦截器，可在main.js中使用
    uni.$request = request
    
    // 添加全局导航拦截器
    uni.addInterceptor('navigateTo', {
      invoke(e) {
        console.log('navigateTo拦截器:', e)
        return e
      },
      success(e) {
        console.log('navigateTo成功:', e)
      },
      fail(err) {
        console.error('navigateTo失败:', err)
      }
    })
    
    // 添加全局跳转拦截器
    uni.addInterceptor('switchTab', {
      invoke(e) {
        console.log('switchTab拦截器:', e)
        return e
      },
      success(e) {
        console.log('switchTab成功:', e)
      },
      fail(err) {
        console.error('switchTab失败:', err)
      }
    })
    
    // 已登录用户，获取用户信息
    if (!isGuest && token) {
      // 加载用户信息
      this.getUserInfo()
    }
  },
  onShow: function() {
    console.log('App Show');
  },
  onHide: function() {
    console.log('App Hide');
  },
  methods: {
    // 获取用户信息
    getUserInfo() {
      // 这里可以调用接口获取用户信息
      // 由于现在只是模拟，直接使用静态数据
      const userInfo = {
        avatar: '/static/images/avatar.gif',
        nickname: '高城词',
        userId: '10086',
        likes: 32,
        following: 12,
        followers: 8
      }
      
      // 保存用户信息
      uni.setStorageSync('userInfo', userInfo)
      this.globalData.userInfo = userInfo
    }
  }
};
</script>

<style lang="scss">
/* 引入公共样式 */
@import '@/static/styles/common.scss';

page {
  background: #f8f8f8;
}

/* 去除页面滚动条 */
::-webkit-scrollbar {
  display: none;
  width: 0 !important;
  height: 0 !important;
  -webkit-appearance: none;
  background: transparent;
}

/* 全局样式 */
page {
  background-color: #f8f8f8;
  font-size: 28rpx;
  color: #333;
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica,
    Segoe UI, Arial, Roboto, 'PingFang SC', 'miui', 'Hiragino Sans GB', 'Microsoft Yahei',
    sans-serif;
}

/* 通用样式 */
.container {
  padding: 20rpx;
  box-sizing: border-box;
}

.flex {
  display: flex;
}

.flex-column {
  display: flex;
  flex-direction: column;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-start {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.flex-end {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

/* 文本样式 */
.text-primary {
  color: #018EFF;
}

.text-success {
  color: #4cd964;
}

.text-warning {
  color: #f0ad4e;
}

.text-error {
  color: #dd524d;
}

.text-gray {
  color: #999;
}

.text-small {
  font-size: 24rpx;
}

.text-large {
  font-size: 32rpx;
}

.text-bold {
  font-weight: bold;
}

/* 间距 */
.mt-10 {
  margin-top: 10rpx;
}

.mt-20 {
  margin-top: 20rpx;
}

.mt-30 {
  margin-top: 30rpx;
}

.mb-10 {
  margin-bottom: 10rpx;
}

.mb-20 {
  margin-bottom: 20rpx;
}

.mb-30 {
  margin-bottom: 30rpx;
}

.ml-10 {
  margin-left: 10rpx;
}

.ml-20 {
  margin-left: 20rpx;
}

.ml-30 {
  margin-left: 30rpx;
}

.mr-10 {
  margin-right: 10rpx;
}

.mr-20 {
  margin-right: 20rpx;
}

.mr-30 {
  margin-right: 30rpx;
}

/* 卡片样式 */
.card {
  background: #fff;
  border-radius: 12rpx;
  padding: 20rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

/* 按钮样式 */
.btn {
  height: 80rpx;
  line-height: 80rpx;
  text-align: center;
  border-radius: 40rpx;
  font-size: 28rpx;
}

.btn-primary {
  background: #018EFF;
  color: #fff;
}

.btn-default {
  background: #f8f8f8;
  color: #333;
}

/* 列表样式 */
.list-item {
  display: flex;
  align-items: center;
  padding: 20rpx;
  background: #fff;
  border-bottom: 1rpx solid #eee;
}

.list-item:last-child {
  border-bottom: none;
}

/* 图片样式 */
.img-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-contain {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter,
.fade-leave-to {
  opacity: 0;
}

.slide-up-enter-active,
.slide-up-leave-active {
  transition: transform 0.3s;
}

.slide-up-enter,
.slide-up-leave-to {
  transform: translateY(100%);
}
</style> 